/******************* 公共变量 *******************/
var userId = core.getUrlData('user_id'),
	userName = core.getUrlData('user_name'),
	fromWhere = core.getUrlData('from'),
	index = core.getUrlData('index'),
	imgArr = (typeof core.ls('reportImage', 'o') == 'string') && JSON.parse(core.ls('reportImage', 'o')),
	swiper;

/******************* 页面数据载入 *******************/
function getData() {
	$.ajax({
		url: (fromWhere == '1') ? photoUrl : selfPhotoUrl,
		type: 'post',
		data: {user_id: userId},
		success: function (data) {
			console.log(data)

			if (data.status == 0) {
				core.layerHint(data.message);
			}
			vm.images = data.list;
		}
	});
}

/******************* Vue初始化代码 *******************/
var vm = new Vue({
	el: '.wrap',
	data: {
		images: [],
		fromWhere: fromWhere,
	},
	methods: {
		deletePhoto: function () {
			var _this = this;
			
			common.layerConfirm({
				content: '确定删除？',
				yesClose: false,
				yes: function () {
					if (fromWhere == 'report') {
						imgArr.splice($('.swiper-slide-active').index(), 1);
						_this.images.splice($('.swiper-slide-active').index(), 1);
						core.ls('reportImage', 'o', JSON.stringify(imgArr));
						core.layerHint('删除成功');
					} else {
						$.ajax({
							url: userPhotoDelUrl,
							type: 'post',
							data: {
								user_id: userId,
								id: _this.images[$('.swiper-slide-active').index()].id
							},
							success: function(data) {
								console.log(data)

								core.layerHint(data.message);
								getData();
							}
						});
					}
				}
			});
		}
	},
	computed: {
		
	},
	components: {
		
	},
	created: function () {
		if (fromWhere == 'report') {
			var images = [];
			for (var i = 0; i < imgArr.length; i++) {
				images.push({
					photo_id: imgArr[i]
				});
			}
			this.images = images;
		} else {
			getData();
		}
	},
	mounted: function () {
		// common.bindBack();
		$('html body .header-back-btn').on('tap', function () {
			core.back();
		});
		$('title').html((fromWhere == 'report') ? '举报图片' : '相册');
		$('.swiper-container').height(winHeight - $('.swiper-pagination').height() - $('footer').height());
		swiper = new Swiper('.swiper-container', {
			pagination: '.swiper-pagination',
			paginationType: 'custom',
			initialSlide: (index ? index : 0),
			paginationCustomRender: function(swiper, current, total) {
				return current + '/' + total;
			}
		});
	},
	updated: function () {
		swiper.update();
		$('.swiper-slide, .swiper-slide span').height(winHeight - $('.swiper-pagination').height() - $('footer').height());
		swiper.slideTo(index ? index : 0, 0, false);
		core.centerImg('html body .wrap .user-album .swiper-container .swiper-wrapper .swiper-slide img', 2);
	}
});

